// pages/locationsDetail/locationsDetail.js

const {
  getByIdApi
} = require("../../public/api");
const {
  baseURL
} = require("../../public/request");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    article: {
      iconpath: "57a37135-66b2-40c0-97a4-d0b102321bf1.png",
      id: 19,
      latitude: 31.247302,
      longitude: 120.569974,
      width: 50,
      height: 50,
      label: {
        content: "西区食堂",
        introduce: '<div style="vertical-align: middle;display: table-cell; text-align: center;" ><img style="width:80%;" src="https://img-blog.csdnimg.cn/5bd503b4bc0d4d7cb803dddd09cfd20a.png"><div>介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍</div></div>',
        anchorx: null,
        color: "#2BA1DF",
        fontsize: 12,
        textalign: "center",
      },
    },
    isAdd: false
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const that = this
    getByIdApi(options.id).then(res => {
      var modifiedHtmlString =
        res.data.data.label.introduce.replace(/src="/g, 'src="' + baseURL + "/common/download?name=");
      that.setData({
        "article.label": res.data.data.label,
        "article.label.introduce": modifiedHtmlString,
        "article.latitude":res.data.data.latitude,
        "article.longitude":res.data.data.longitude
      });
    }).catch(err => {
      console.log('失败回调', err)
    })
  },


  toTarget() {
    const _this = this
    wx.openLocation({
      latitude: Number(_this.data.article.latitude),
      longitude: Number(_this.data.article.longitude),
      name: _this.data.article.label.content,
      scale: 28
    })  
  }
})